package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.audit.pojo.vo.AuditVO;
import cn.tedu.ivos.audit.service.AuditService;
import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.user.mapper.UserMapper;
import cn.tedu.ivos.user.pojo.vo.UserVO;
import cn.tedu.ivos.vehicle.mapper.VehicleMapper;
import cn.tedu.ivos.vehicle.pojo.entity.Vehicle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/v1/application/")
public class ApplicationController {
    @Autowired
    ApplicationService applicationService;
    @PostMapping("save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam){
        log.debug("新增申请单:参数{}",applicationSaveParam);
        applicationService.save(applicationSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult selectApplication(ApplicationQuery applicationQuery){
        log.debug("查询申请单:参数{}",applicationQuery);
        List<ApplicationVO> list = applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("cancel/{id}")
    public JsonResult cancelApplication(@PathVariable Long id){
        log.debug("撤销申请单:参数{}",id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }

    @PostMapping("distribute/{applicationId}/{vehicleId}")
    public JsonResult distributeApplication(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("分配车辆,参数{},{}",applicationId,vehicleId);
        applicationService.distributeApplication(applicationId,vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("back/{applicationId}/{vehicleId}")
    public JsonResult backApplication(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("归还车辆,参数={},{}",applicationId,vehicleId);
        applicationService.back(applicationId,vehicleId);
        return JsonResult.ok();
    }
}
